
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绿色医院登录系统</title>
    <style>
        body.hospital-login {
        font-family: Arial, sans-serif;
            background-image: linear-gradient(to bottom right,#fbc2eb, #a6c1ee);
            /* 渐变色背景 */
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        margin: 0;
        overflow: hidden; /* 防止滚动条 */
        animation: fadeIn 1s ease-in-out; /* 添加淡入动画 */
    }

    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    .login-container {
        background-color: rgb(255, 255, 255);
        width: 400px;
        height: 500px;
        border-radius: 15px;
        padding: 0 50px;
        position: relative;
        left: 20%;
        top: 20%;
        transform: translate(-50%, -50%);
    }

    @keyframes slideIn {
        from { transform: translateY(-100%); }
        to { transform: translateY(0); }
    }

    input[type="tel"], input[type="password"] {
        display: block;
        width: 100%;
        margin-bottom: 20px;
        border: 0;
        padding: 10px;
        border-bottom: 1px solid rgb(128, 125, 125);
        font-size: 15px;
        outline: none;
    }

    input[type="tel"]:focus, input[type="password"]:focus {
        border-color: #cb95f1; /* 焦点时更亮的绿色 */
    }

    .denglu {
        width: 40%;
        padding: 10px;
        background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
        text-align: center;
        color: white;
        border: none;
        cursor: pointer;
        border-radius: 4px;
        transition: background-color 0.3s;
        left: 20px;
    }
    .zhuce{
        width: 40%;
        padding: 10px;
        background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
        text-align: center;
        color: white;
        border: none;
        cursor: pointer;
        border-radius: 4px;
        transition: background-color 0.3s;
    }

    button:hover {
        background-color: #0056b3;
    }

    .message {
        color: #ff0000; /* 红色错误消息 */
        display: none; /* 初始隐藏 */
        animation: fadeOut 1s ease-in-out forwards 1s; /* 添加淡出动画 */
    }

    .message.visible {
        display: block; /* 显示错误消息 */
    }

    @keyframes fadeOut {
        from { opacity: 1; }
        to { opacity: 0; }
    }
        .header {
            font-size: 30px;
            font-weight: bold;
            text-align: center;
            line-height: 200px;
        }
        /* 新增CSS规则，用于控制按钮的布局 */
        .login-buttons {
            display: flex;
            justify-content: space-around;
            width: 100%;
        }

        .denglu, .zhuce {
            /* 移除内联样式中的margin，并在这里设置为合适的值，如果需要的话 */
            /* margin: 0; */
            /* 根据需要调整宽度，以适应容器 */
            width: 48%; /* 或其他适合的宽度，确保两者相加不超过100% */
        }
    </style>
</head>
<body class="hospital-login">
<div class="login-container">
    <div class="header">社区儿童疫苗接种系统登录</div>
    <form id="loginForm">
        <label for="phone">电话号码:</label>
        <input type="tel" id="phone" name="phone" required>
        <label for="password">密码:</label>
        <input type="password" id="password" name="password" required>
    </form>
    <div class="login-buttons">
        <button class="denglu" id="s-btn" type="submit">登录</button>
        <button class="zhuce" id="register">注册</button>
    </div>
    <p class="message" id="errorMessage"></p>
</div>
<script>
    document.getElementById('register').addEventListener('click', function() {
        window.location.href = 'register.html';
    });


    document.getElementById('s-btn').addEventListener('submit', function(event) {
        event.preventDefault();

        const phone = document.getElementById('phone').value;
        const password = document.getElementById('password').value;
        console.log(phone, password)
        fetch('./loginservlet?phone='+phone+'&password='+password, {
            method: 'POST',
        })
            .then(response => {
                if (!response.ok) {
                    throw new Error('网络错误');
                }
                return response.text();
            })
            .then(data => {
                console.log(data)
                if (data==="1"||data==="2") {
                    if(data==="1"){
                        window.location.href = '/web/admin.html';
                    }else{
                        window.location.href = '/web/common.html';
                    }
                } else {
                    document.getElementById('errorMessage').classList.add('visible'); // 显示错误消息
                    document.getElementById('errorMessage').textContent = "该账户未注册";
                    setTimeout(() => {
                        document.getElementById('errorMessage').classList.remove('visible'); // 隐藏错误消息
                    }, 3000);
                }
            })
            .catch(error => {
                console.error('登录请求失败:', error);
                document.getElementById('errorMessage').classList.add('visible');
                document.getElementById('errorMessage').textContent = '登录失败，请重试';
                setTimeout(() => {
                    document.getElementById('errorMessage').classList.remove('visible');
                }, 3000);
            });
    });

</script>
</body>
</html>
